# -*- encoding:utf-8 -*-
# @Time: 2022/10/26 20:45
# @Author : moran
# @Email: moran@maqu.com
# @File: modelsMixin.py
# @Software: PyCharm

from django.db import models

class DataTimeModelMixin(models.Model):
    """
        创建时间和修改时间的拓展类
    """
    create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    update_time = models.DateTimeField(auto_now=True, verbose_name='更新时间')

    class Meta:
        abstract = True  # 指定该类为抽象类，迁移映射的时候不会生成对应的数据表

class IsDeleteModelMixin(models.Model):
    """
    逻辑删除拓展类
    """
    is_delete = models.BooleanField(default=False, verbose_name='逻辑删除')

    # 逻辑删除
    def delete(self, using=None, keep_parents=False):
        self.is_delete = True
        self.save()

    class Meta:
        abstract = True  # 指定该类为抽象类，迁移映射的时候不会生成对应的数据表

class ModelSetMixin(DataTimeModelMixin, IsDeleteModelMixin):
    """
    模型拓展类的整合
    """
    class Meta:
        abstract = True  # 指定该类为抽象类，迁移映射的时候不会生成对应的数据表